
import mitt from 'mitt';
const emitter = mitt();
const events = {};
import { reactive } from 'vue';
const eventBus = reactive({
  on(event, callback) {
    if (!events[event]) events[event] = [];
    events[event].push(callback);
  },
  off(event, callback) {
    if (!events[event]) return;
    if (callback) {
      events[event] = events[event].filter(cb => cb !== callback);
    } else {
      delete events[event];
    }
  },
  emit(event, ...args) {
    if (events[event]) {
      events[event].forEach(callback => callback(...args));
    }
  }
});
export default eventBus;
